import java.util.*;
/*给你一个下标从 0 开始的字符串数组 words 以及一个二维整数数组 queries 。
每个查询 queries[i] = [li, ri]
 会要求我们统计在 words 中下标在 li 到 ri 范围内（包含 这两个值）并且以元音开头和结尾的字符串的数目。
返回一个整数数组，其中数组的第 i 个元素对应第 i 个查询的答案。
注意：元音字母是 'a'、'e'、'i'、'o' 和 'u' 。
输入：words = ["aba","bcb","ece","aa","e"], queries = [[0,2],[1,4],[1,1]]
输出：[2,3,0]
 */
public class Main {
    public static int[] check(String[] s, int[][] queries) {
        int n = s.length;
        int[] nums = new int[n];
        int m = queries.length;
        for (int i = 0; i < n; i++) {
            nums[i] = change(s[i]);
        }
        int[] result = new int[n + 1];
        for (int i = 0; i < n; i++) {
            result[i + 1] = result[i] + nums[i]; // 前缀和
        }
        int[] x = new int[m];
        for (int i = 0; i < m; i++) {
            int l = queries[i][0];
            int r = queries[i][1];
            x[i] += result[r + 1] - result[l];
        }
        return x;
    }

    public static int change(String a) {
        char[] r = a.toCharArray();
        int x = r.length;
        if ((r[0] == 'a' || r[0] == 'e' || r[0] == 'i' || r[0] == 'o' || r[0] == 'u')
                && (r[x - 1] == 'a'
                || r[x - 1] == 'e'
                || r[x - 1] == 'i'
                || r[x - 1] == 'o'
                || r[x - 1] == 'u')) {
            return 1;
        }
        return 0;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String[] s = new String[n];
        for (int i = 0; i < n; i++) {
            s[i] = sc.nextLine();
        }
        int m = sc.nextInt();
        int[][] queries = new int[m][2];
        for (int i = 0; i < m; i++) {
            queries[i][0] = sc.nextInt();
            queries[i][1] = sc.nextInt();
        }
        int[] res = check(s, queries);
        System.out.println(Arrays.toString(res));
    }
}